(ns ui
  (:require psystem.psys))

(import '(javax.swing JLabel JFrame JPanel JTextField BorderFactory JButton ButtonGroup JRadioButton JComponent)
	'(javax.swing.event DocumentListener)
	'(java.awt GridBagLayout GridBagConstraints Insets Color Dimension FlowLayout GridLayout Graphics)
	'(java.awt.image BufferedImage)
	'(java.awt.event ActionListener))


(def title-label
     (new JLabel "Generative P System"))


(def run-button
     (doto (new JButton "Run")
       (. addActionListener (proxy [ActionListener] []
			      (actionPerformed [e] (println "Button Pressed"))))))


(def six-choice-panel
     (let [button-group (doto (ButtonGroup.)
			  (.add (new JRadioButton))
			  (.add (new JRadioButton))
			  (.add (new JRadioButton))
			  (.add (new JRadioButton))
			  (.add (new JRadioButton))
			  (.add (new JRadioButton)))]
       (doto (JPanel.)
	 (.setLayout (new GridLayout 3 2))
	 (.setBackground (. Color lightGray))
	 (.setBorder (. BorderFactory createTitledBorder "Choices, Choices"))
	 (.add (new JRadioButton))
	 (.add (new JRadioButton))
	 (.add (new JRadioButton))
	 (.add (new JRadioButton))
	 (.add (new JRadioButton))
	 (.add (new JRadioButton)))))


(defn new-image []
  (BufferedImage. 200 200 (BufferedImage/TYPE_INT_ARGB)))


(defn scribble [g]
  (let [buffer (new-image)
	graphics (.getGraphics buffer)]
    (.setColor graphics Color/BLACK)
    (.fillRect graphics 0 0 200 200)
    (.setColor graphics Color/BLUE)
    (.fillRect graphics 0 50 20 20)  
    (.drawImage g buffer 0 0 nil)))


(def draw-component
     (doto
	 (proxy [JPanel] []
	   (paint [g] (scribble g)))))
       

(def draw-panel
     (doto (JPanel.)
       (.setOpaque true)
       (.setLayout (new FlowLayout))
       (.setPreferredSize (new Dimension 300 300))
       (.add draw-component)
       (.setBorder (. BorderFactory createLineBorder (. Color gray) 5))))


(def result-panel
     (doto (JPanel.)
       (.setOpaque true)
       (.setLayout (new FlowLayout))
       (.setPreferredSize (new Dimension 300 300))
       (.setBorder (. BorderFactory createLineBorder (. Color gray) 5))))
       

(def main-panel
     (doto (JPanel.)
       (.setOpaque true)
       (.setBackground (new Color 220 220 223)) 
       (.add run-button)
       (.add draw-component)
       (.add draw-panel)
       (.add result-panel)
       (.add six-choice-panel)
       (.setPreferredSize (new Dimension 300 300))))


(defn psystem-app []
  (doto
      (JFrame. "Generative Aesthetics with P Systems")
    (.setContentPane main-panel)
    (.setSize 900 400)
    (.setVisible true)))

